package com.hp.team.bookstore.model.order;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import com.hp.team.bookstore.model.profile.Customer;

@Entity
@Table(name = "SALES_ORDER")
public class SalesOrder extends Order {

	@OneToOne
	@JoinColumn(name = "CUSTOMER_ID")
	private Customer customer;

	@Enumerated(EnumType.STRING)
	@Column(name = "STATUS")
	private SOStatus status;

	@OneToMany(mappedBy = "order", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
	private Set<SalesOrderItem> orderItems = new HashSet<SalesOrderItem>();

	public Customer getCustomer() {
		return customer;
	}

	public void setCustomer(Customer customer) {
		this.customer = customer;
	}

	public SOStatus getStatus() {
		return status;
	}

	public void setStatus(SOStatus status) {
		this.status = status;
	}

	public Set<SalesOrderItem> getOrderItems() {
		return orderItems;
	}

	public void setOrderItems(Set<SalesOrderItem> orderItems) {
		this.orderItems = orderItems;
	}

	public void addOrderItem(SalesOrderItem orderItem) {
		if (orderItems == null) {
			orderItems = new HashSet<SalesOrderItem>();
		}

		for (SalesOrderItem item : orderItems) {
			System.out.println("Equality: " + orderItem.equals(item));
		}

		orderItems.add(orderItem);
	}
}
